const path = require('path');
const os = require('os');
const HappyPack = require('happypack');
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
function resolve(dir) {
	return path.join(__dirname, dir);
}
module.exports = {
	runtimeCompiler: true,
	publicPath: process.env.NODE_ENV === 'production' ? './' : './',
	// 禁用es
	lintOnSave: false,
	productionSourceMap: false,
	css: {
		loaderOptions: {
			less: {
				lessOptions: {
					modifyVars: {
						'primary-color': '#8A2BE2'
					},
					javascriptEnabled: true
				}
			}
			// sass:{}
		}
	},
	configureWebpack: {
		optimization: {
			splitChunks: {
				chunks: 'all',
				maxSize: 0,
				minChunks: 3,
				maxAsyncRequests: 6,
				maxInitialRequests: 4,
				automaticNameDelimiter: '~',
				cacheGroups: {
					// defaultVendors: {
					// 	test: /[\\/]node_modules[\\/]/,
					// 	priority: -10
					// },
					default: {
						name: 'wy_Vue',
						minChunks: 2,
						priority: -20,
						reuseExistingChunk: true
					}
				}
			}
		},
		// module: {
		// 	rules: [
		// 		{
		// 			test: /\.(jsx|js)$/,
		// 			//把对.js 的文件处理交给id为happyBabel 的HappyPack 的实例执行
		// 			loader: 'happypack/loader?id=happyBabel',
		// 			//排除node_modules 目录下的文件
		// 			exclude: /node_modules/
		// 		}
		// 	]
		// },
		// plugins: [
		// 	new HappyPack({
		// 		//用id来标识 happypack处理那里类文件
		// 		id: 'happyBabel',
		// 		//如何处理  用法和loader 的配置一样
		// 		loaders: ['babel-loader?cacheDirectory=true'],
		// 		//共享进程池
		// 		threadPool: happyThreadPool,
		// 		//允许 HappyPack 输出日志
		// 		verbose: true
		// 	})
		// ]
	},
	chainWebpack: (config) => {
		config.resolve.alias.set('TOOL', resolve('src/tool')).set('FLY', resolve('src/fly')).set('BUS', resolve('src/bus'));
	},
	// 服务
	devServer: {
		port: '8888',
		proxy: {
			'/API': {
				target: 'http://srbzqtest.auxgroup.com/',
				changeOrigin: true,
				pathRewrite: {
					'^/API': '' // 思路是如果是开发环境，就给所有要代理的接口统一加上前缀，然后代理请求时再统一通过rewrite去掉
				}
			}
		}
	}
};
